<?php

ini_set('memory_limit', '4G');


use model\MMemoryWords;

global $anticipated;
//$anticipated = 0.001;


$list = MMemoryWords::select('word');
$exists = array_combine($list, $list);
$file = '/data/logs/words_all.log';
$file2 = '/data/logs/words_all_bak.log';
$instance = new CFileSystem($file, 'c+');
$instance2 = new CFileSystem($file2, 'w+');


$content = $instance->read();
$arr = explode("\n", $content);

$uniq = [];

foreach ($arr as $v) {
    if (empty($v)) continue;
    list($word, $explain) = explode("|||", $v);
    //清除无用解释
    $tempExplain = explode('$$$', $explain);
    foreach ($tempExplain as $key => $vv) {
        $vv = trim($vv);
        if ($vv === 'none'|| $vv === '无') unset($tempExplain[$key]);
    }
    $explain = empty($tempExplain) ? '' : implode('$$$', $tempExplain);
    if (count(explode(' ', $word)) > 1) {
        //词组

    } else {
        //单词
        $word = strtolower($word);
    }

    $values = [
        'name' => $word,
        'intro' => $explain,
    ];
    MMemoryWords::insert($values);
}

